/*
 * @Author: Wushiqi
 * @Descripttion: 
 * @Date: 2020-07-26 13:38:50
 * @LastEditors: Wushiqi
 * @LastEditTime: 2020-10-22 21:40:31
 */
import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

// export default new Router(
  const routes = [
    {
      path: '/',
      component: () => import('@/views/Home'),
      meta: {
        keepalive: true
      }
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/register')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login')
    },
    {
      path: '/userInfo',
      name: 'userInfo',
      component: () =>import('@/views/userInfo'),
      meta: {
        isToken: true
      }
    },
    {
      path: '/edit',
      name: 'edit',
      component: () =>import('@/views/Edit'),
      meta: {
        isToken: true
      }
    },
    {
      path: '/article/:id', // 动态路由
      name: 'article',
      component: () => import('@/views/Article')
    },
    {
      path: '/editcategory',
      name: 'editcategory',
      component: () =>import('@/views/EditCategory')
    }
  ]
// )
const router = new Router({
  routes,
  mode: 'history'
})

router.beforeEach((to, from, next) =>{
  if (!localStorage.getItem('token') && !localStorage.getItem('id') && to.meta.isToken === true) {
    router.push('/login')
    Vue.prototype.$msg.fail('请重新登录')
    return
  } else {
    next()
  }
})

export default router
